#include <iostream>
#include <map>
using namespace std;
typedef long long LL;
const LL MOD = 998244353;

LL qpow(LL a, LL b, LL p)
{
    LL ret = 1;
    while(b)
    {
        if(b & 1) ret = ret * a % p;
        b >>= 1;
        a = a * a % p;
    }
    return ret;
}

int main()
{
    int n; cin >> n;
    int T = 2 * n;
    map<int, int> mp;
    LL ans = 1;
    LL cnt = 0; // mp里面有多少数
    LL up = 1, down = 1;    
    LL pre_max = -1;
    while(T--)
    {
        int x; cin >> x;

        if(x != -1) 
        {
            if(x < pre_max) 
            {
                cout << 0 << endl;
                return 0;
            }
            mp[x]++;
            cnt++;
        }
        else 
        {
            for(auto t : mp)
            {
                LL a = t.first, b = t.second;
                // cout << b << " " << cnt << endl;
                ans = ans * b % MOD * qpow(cnt, MOD - 2, MOD) % MOD;  
                mp[a]--;
                pre_max = a;
                cnt--;
                if(mp[a] == 0) mp.erase(a);
                break;
            } 
        }
    }
    cout << ans << endl;
    return 0;
}
